package com.example.administrator.yuejian_2.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.administrator.yuejian_2.R;
import com.example.administrator.yuejian_2.activity.TrainDetailActivity;
import com.example.administrator.yuejian_2.bean.TrainListBean;
import com.example.administrator.yuejian_2.viewholder.TrainListViewHolder;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/10/19.
 */

public class TrainListAdapter extends RecyclerView.Adapter {


    private List<TrainListBean> train = new ArrayList<>();
    private Context context;
    private LayoutInflater layoutInflater;

    public TrainListAdapter(Context context, List<TrainListBean> train){
        this.context = context;
        layoutInflater = LayoutInflater.from(context);
        this.train.addAll(train);

    }




    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = layoutInflater.inflate(R.layout.item_train,parent,false);
        TrainListViewHolder holder = new TrainListViewHolder(itemView);
        return holder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        TrainListViewHolder trainholder = (TrainListViewHolder) holder;
        TrainListBean trainlist = train.get(position);
        trainholder.trainname.setText(trainlist.getCourse_name());
        String train_picture = trainlist.getCourse_pic();
        if (!train_picture.equals(""))
            Picasso.with(context).
                    load("http://10.0.2.2/yuejian16/Public/clubphoto/"+train_picture)
                    .into(trainholder.trainpic);

        final int train_id = trainlist.getCourse_id();
        trainholder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(context, TrainDetailActivity.class);
                intent.putExtra("train_id",train_id);
                context.startActivity(intent);

            }
        });


    }

    @Override
    public int getItemCount() {

        return train.size();
    }
}

